/**
 * @filename:UserController 2019年4月9日
 * @project wallet-manage  V1.0
 * Copyright(c) 2018 BianPeng Co. Ltd.
 * All right reserved.
 */
package Generator;

import Utils.DBUtil;
import com.gitee.flying.cattle.mdg.entity.BeanGenInfo;
import com.gitee.flying.cattle.mdg.util.EntityInfoUtil;
import com.gitee.flying.cattle.mdg.util.Generator;
import com.gitee.flying.cattle.mdg.util.MySqlToJavaUtil;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;

/**
 * Copyright: Copyright (c) 2019
 *
 * <p>
 * 说明： 自动生成工具
 * </P>
 * <p>
 * 源码地址：https://gitee.com/flying-cattle/mybatis-dsc-generator
 * </P>
 */
public class CodeGenMain {
    // 基础信息：项目名、作者、版本
    public static final String PROJECT = "river";
    public static final String AUTHOR = "liuyu";
    public static final String VERSION = "V1.0";
    // 数据库连接信息：连接URL、用户名、秘密、数据库名
    public static final String URL = "jdbc:mysql://192.168.139.139:3306/river?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8";
    public static final String NAME = "root";
    public static final String PASS = "arcgis";
    public static String DATABASE = "";
    /*
     * // 类信息：类名、对象名（一般是【类名】的首字母小些）、类说明、时间 public static final String CLASSNAME =
     * "user"; public static final String TABLE = "user";
     */

    public static final String CLASSCOMMENT = "平台申请";
    public static final String TIME = "2019年5月5日";

    // 路径信息，分开路径方便聚合工程项目，微服务项目
    public static final String ENTITY_URL = "com.entity";
    public static final String DAO_URL = "com.dao";
    public static final String XML_URL = "com.daoimpl";
    public static final String SERVICE_URL = "com.service";
    public static final String SERVICE_IMPL_URL = "com.serviceimpl";
    public static final String CONTROLLER_URL = "com.controller";
    // 是否是Swagger配置
    public static final String IS_SWAGGER = "true";

    public static void main(String[] args) throws SQLException {

        Connection conn = DBUtil.getConnection(URL, NAME, PASS);
        DATABASE = conn.getCatalog();
        int iCount = 0;
        // 获取表
        List<String> tableNames = DBUtil.getTableNames(conn);
//		tableNames.clear();
//
//		tableNames.add("monitor");


        System.out.println("tableNames:" + tableNames);
        for (String tableName : tableNames) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }    //延时2秒
            String AGILE = new Date().getTime() + "";
            String CLASSNAME = tableName;
            String TABLE = tableName;
            BeanGenInfo bi = new BeanGenInfo(PROJECT, AUTHOR, VERSION, URL, NAME, PASS, DATABASE, TIME, AGILE, ENTITY_URL,
                    DAO_URL, XML_URL, SERVICE_URL, SERVICE_IMPL_URL, CONTROLLER_URL, IS_SWAGGER);
            bi.setTable(TABLE);
            bi.setEntityName(MySqlToJavaUtil.getClassName(TABLE));
            bi.setObjectName(MySqlToJavaUtil.changeToJavaFiled(TABLE));
            bi.setEntityComment(CLASSCOMMENT);


            bi.setEntityLombokModel(false);
            bi = EntityInfoUtil.getInfo(bi);
            String projectPath = System.getProperty("user.dir");
            String fileUrl = projectPath + "\\src\\main\\java\\";// 生成文件存放位置

            String aa1 = Generator.createEntity(fileUrl, bi).toString();

            String aa2 = Generator.createDao(fileUrl, bi).toString();
            String aa3 = Generator.createMapperXml(fileUrl, bi).toString();
//        	String aa4 = Generator.createService(fileUrl, bi).toString();
            //  String aa5 = Generator.createServiceImpl(fileUrl, bi).toString();*/
            String aa6 = Generator.createController(fileUrl, bi).toString();


            if (iCount == 0) {
                // 是否创建swagger配置文件
                String aa7 = Generator.createSwaggerConfig(fileUrl, bi).toString();
                System.out.println(aa7);
            } else {

            }

            iCount++;

        }
    }
}
